package com.lmk.utils;

import java.util.Arrays;

public class work02 {

    public static int removeDuplicates(int[] nums) {
        int len = nums.length;
        if (0 == len)
        {
            return 0;
        }
        int prev = nums[0]; // 前一个元素
        int newLen = 1;
        for (int i = 1; i < len; i++)
        {
            int num = nums[i];
            if (num != prev)
            {
                nums[newLen] = num;
                newLen++;
                prev = num;
            }
        }
        return newLen;


    }

    public static void main(String[] args) {
        int[]a={1,1,2,};
    removeDuplicates(a);
        System.out.println(Arrays.toString(a));

    }
}



